
#include "../stdafx.h"
#include "BaseFileOp.h"


CBaseFileOp::CBaseFileOp()
{

}

CBaseFileOp::~CBaseFileOp()
{

}



bool CBaseFileOp::ReadChar(CFile * fp, unsigned char &retv)
{
	if(fp->Read(&retv,sizeof(unsigned char))!= sizeof(unsigned char))
	{
		return false;
	}
	return true;
}

bool CBaseFileOp::WriteChar(CFile * fp, unsigned char &v)
{
	fp->Write(&v,sizeof(unsigned char));
	return true;
}


bool CBaseFileOp::ReadFloat(CFile * fp, double &retv)
{
	if(fp->Read(&retv,sizeof(double))!= sizeof(double))
	{
		return false;
	}
	return true;
}

bool CBaseFileOp::WriteFloat(CFile * fp, double &v)
{
	fp->Write(&v,sizeof(double));
	return true;
}
bool CBaseFileOp::ReadFloat32(CFile * fp, float &retv)
{
	if(fp->Read(&retv,sizeof(float))!= sizeof(float))
	{
		return false;
	}
	return true;
}

bool CBaseFileOp::WriteFloat32(CFile * fp, float &v)
{
	fp->Write(&v,sizeof(float));
	return true;
}
bool CBaseFileOp::ReadInt64(CFile * fp, INT64 &retv)
{
	if(fp->Read(&retv,sizeof(INT64))!= sizeof(INT64))
	{
		return false;
	}
	return true;
}

bool CBaseFileOp::WriteInt64(CFile * fp, INT64 &v)
{
	fp->Write(&v,sizeof(INT64));
	return true;
}



bool CBaseFileOp::ReadInt(CFile * fp, long &retv)
{
	if(fp->Read(&retv,sizeof(long))!= sizeof(long))
	{
		return false;
	}
	return true;
}

bool CBaseFileOp::WriteInt(CFile * fp, long &v)
{
	fp->Write(&v,sizeof(long));
	return true;
}

bool CBaseFileOp::WriteString(CFile * fp,CString & s)
{
	long ssize;
	ssize = s.GetLength();
	fp->Write(&ssize,sizeof(long));
	fp->Write(s.GetBufferSetLength(ssize + 1),ssize);
	return true;
}

bool CBaseFileOp::ReadString(CFile * fp,CString & rets)
{
	rets.Empty();
	long ssize;
	if(fp->Read(&ssize,sizeof(long)) != sizeof(long))
	{
		return false;
	}
	char tmp[1025];
	long times = ssize / 1024;
	long relic = ssize %1024;
	for(long i = 0; i < times ; i ++)
	{
		fp->Read(tmp,1024);
		tmp[1024] = '\0';
		rets += tmp;
	}
	if(relic !=0)
	{
		fp->Read(tmp,relic);
		tmp[relic] = '\0';
		rets += tmp;
	}
	return true;

}
